<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
	$(function(){
	
		bindDict("provincecode","DM_SF", null, null);
		initFileInput2('upload', {'busscode': '04'}, null);
		$('#provincecode').change(function(){
			var selectID = 'citycode';
			$.ajax({
				url: projectPath + "dict/getDictDetail.do",
				data: {"dictcode": "DM_CS", "bigClass": $(this).val()},
				dataType: "json",
				success: function(data){
					// 先清空控件数据
					$('#' + selectID).empty(); 
					
					if(data.result == 1){   
						var dataStr = data.datas;
		
						var option = $("<option>").val("").text(""); 
						$('#' + selectID).append(option); 
						
						for (var i = 0; i < dataStr.length; i++) {
							var value = dataStr[i].itemcode;
							var text = dataStr[i].itemname;
							
							var option = $("<option>").val(value).text(text); 
							$('#' + selectID).append(option); 
						}	
					}
		    	}
			});
		});
	});
	
	
	//选中与取消选中
	function permanentchange(permanent){
		var index=$(permanent).attr("id").substring(10);
		if($(permanent).is(":checked")){
			if($(permanent).attr("id").indexOf("permanenty")>-1){
				$("#permanentn"+index).removeAttr("checked");
			}else{
				$("#permanenty"+index).removeAttr("checked");
			}
		}else{
			if($(permanent).attr("id").indexOf("permanenty")>-1){
				$("#permanenty"+index).prop("checked","checked");
			}else{
				$("#permanentn"+index).prop("checked","checked");
			}
		}
	}
	
	function addrecordcertificate(){
		
		var html = ''+
		  '	<tr>'+
		  '		<td>'+
		  '			<select class="form-control" name="certificatetype" id="certificatetype'+nowindex+'">'+
		  '			<input type="hidden"  class="form-control" name="recordtype"  value="2"></td>'+
		  '		<td>'+
		  '			<input type="date" class="form-control" name="issuedate" id="issuedate'+nowindex+'">'+
		  '		</td>'+
		  '		<td>'+
		  '			<input type="date" class="form-control" name="effectivedate" id="effectivedate'+nowindex+'">'+
		  '		</td>'+
	//	  '		<td>'+
	//	  '			是<input type="checkbox" onclick="permanentchange(this)" name="permanent"  value="1" id="permanenty'+nowindex+'">否<input type="checkbox" onclick="permanentchange(this)" name="permanent" checked value="0" id="permanentn'+nowindex+'">'+
	//	  '		</td>'+
		  '		<td id="filename_'+ nowindex +'"></td>'+
		  '	    <td><button type="button"  onclick="openModal('+nowindex+')" class="btn btn-success" ><span class="glyphicon glyphicon-upload"></span>上传</button>'+
		  '			<input type="hidden" id="upload_'+nowindex+'" class="form-control" name="fileid"  value=""></td>'+
		  '		<td>'+
		  '			<button type="button"  onclick="deleterecordcertificate(this)" class="btn btn-danger btn-sm" style="margin-right:10px;"><span class="glyphicon glyphicon-minus"></span></button>'+
		  '		</td>'+
		  '	</tr>';	
		
		$("#recordcertificate").find('tbody').append(html);
		bindDict("certificatetype"+nowindex,"DM_DWBAZSLX",null);
		nowindex++;
		
	}
	
	function deleterecordcertificate(button){
		$(button).parent().parent().remove();
	}
	
	function initFileInput2(ctrlcss, params, data) {
	
		var urls = [];
		if(data != null){
			for(var i = 0; i < data.length; i++){
				urls[i] = data[i].url;
			}
		}
		
	    var control = $('.' + ctrlcss);
	    control.fileinput({
	        theme: 'explorer-fa',
	        language: 'zh', //设置语言
	        uploadUrl: projectPath + "upload_fileinput.do", //上传的地址
	//         allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
	        uploadExtraData: params,
	        uploadAsync: true, //默认异步上传
	        showUpload: true, //是否显示上传按钮
	        showRemove : true, //显示移除按钮
	        showPreview : true, //是否显示预览
	        showCaption: false,//是否显示标题
	        browseClass: "btn btn-primary", //按钮样式
	        enctype: 'multipart/form-data',
	        validateInitialCount:true,
	        overwriteInitial: false,
	        initialPreviewAsData: true,
	        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
	        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
	        initialPreview: urls,
		    initialPreviewConfig: data,
	
	    }).on('filepreupload', function(event, data, previewId, index) {     //上传中
	        var form = data.form, files = data.files, extra = data.extra,
	        response = data.response, reader = data.reader;
	        console.log('文件正在上传');
	    }).on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
	        console.log('文件上传成功！');
	        
	        var resultData = data.response;
	        var fileid = resultData.datas[0].fileid;
	        var filename = '<p id="'+ fileid +'"><a href="/gahCMP/downFiles.do?filename='+ resultData.datas[0].filename +'&fileid='+ fileid +'">' + resultData.datas[0].filename + '</a><span class="glyphicon glyphicon-remove" style="color:red;cursor:pointer;" onclick="deleteFile(\''+ nowindex +'\', \''+ fileid +'\')"></span></p>';
	        var fileids = $('#upload_' + nowindex).val();
	        var filenames = $('#filename_' + nowindex).html();
	        if(fileids == ''){
	        	fileids = fileid;
	        	filenames = filename;
	        }
	        else{
	        	fileids += ',' + fileid;
	        	filenames += filename;
	        }
	
	        $('#upload_' + nowindex).attr("value", fileids);
	        
	        $('#filename_' + nowindex).html(filenames);
	
	    	$('#fileuploadmodal').modal('hide');
	        
	    }).on('fileerror', function(event, data, msg) {  //一个文件上传失败
	        console.log('文件上传失败！'+data.id);
	    }).on('filepredelete', function(event, key, jqXHR, data) {  
	        window.wxc.xcConfirm(key, window.wxc.xcConfirm.typeEnum.info);
	        return;
	    });  
	}
</script>
</head>
<body>

	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">业务资料</h3>
		</div>

		<div class="panel-body">
			<form id="Business">
				<table class="table table-bordered">
					<tbody>
						<tr>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								中文名称：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control" name="companyname" placeholder="请输入中文名称">
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								组织机构代码：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control" name="companycode" placeholder="请输入组织机构代码">
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								法人代表：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control" name="corporation" placeholder="请输入法人代表">
							</td>
						</tr>
						<tr>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								英文名称：
							</td>
							<td>
    							<input type="text" class="form-control" name="companynameen">
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								联系人：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control"  name="contactperson" placeholder="请输入联系人">
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								联系电话：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control"  name="contactphone" placeholder="请输入联系电话">
							</td>
						</tr>
						<tr>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								注册省份：<span style="color:red;">*</span>
							</td>
							<td>
    							<select class="form-control" name="provincecode" id="provincecode" onchange="changeCity(this.value)" placeholder="请选择注册省份"></select>
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								注册城市：<span style="color:red;">*</span>
							</td>
							<td>
    							<select class="form-control" name="citycode" id="citycode" placeholder="请选择注册城市"></select>
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								注册街道：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" class="form-control"  name="street" placeholder="请输入注册街道">
							</td>
						</tr>
						<tr>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								经营地址：<span style="color:red;">*</span>
							</td>
							<td colspan="3">
    							<input type="text" class="form-control" name="businessaddress" placeholder="请输入经营地址">
							</td>
							<td style="width:130px; text-align: right; background-color: #eee; ">
								邮箱：<span style="color:red;">*</span>
							</td>
							<td>
    							<input type="text" t="email" class="form-control" name="email" placeholder="请输入邮箱">
    							<script type="text/javascript" src="../../js/data-validate.js"></script>
							</td>
						</tr>
					</tbody>
				</table>
            </form>
		</div>
	</div>
	<div class="panel panel-primary">
		<div class="panel-heading" style=" position: relative">
			<span style="font-size: 16px;">提交材料</span>
			<button type="button" class="btn btn-success" onclick="addrecordcertificate()" style="height:30px; float: right;">添加</button>
		</div>
			
		<table class="table"  style="text-align: center;" id="recordcertificate">
			<thead>
				<tr>
					<th style="width: 20%; text-align: center;">证书类型</th>
					<th style="width: 15%; text-align: center;">签发日期</th>
					<th style="width: 15%; text-align: center;">有效截止日期</th>
					<!-- <th style="width: 10%; text-align: center;">是否长期有效</th> -->
					<th style="width: 30%; text-align: center;">附件</th>
					<th style="width: 5%; text-align: center;">操作</th>
					<th style="width: 5%; text-align: center;">删除</th>
				<tr>
			</thead>
			<tbody >
					
			</tbody>
		</table>
			
	</div>
</body>
</html>